import { toRaw } from 'vue'
import * as monaco from 'monaco-editor'
import type { BwMonacoEditorMenuModel } from '../model'

/**
 * 创建菜单
 * keybindings:monaco.KeyMod.Alt | monaco.KeyMod.Shift | monaco.KeyCode.KeyF
 */
export const createMenus = (
  editor: monaco.editor.IStandaloneCodeEditor,
  menus?: Array<BwMonacoEditorMenuModel>
) => {
  if (editor) {
    if (menus) {
      menus.forEach((item) => {
        toRaw(editor)?.addAction({
          id: item.id,
          label: item.label,
          keybindings: item.keybindings,
          contextMenuGroupId: item.contextMenuGroupId,
          run: item.run,
        })
      })
    }
  }
}
